package http

import (
	"github.com/gin-gonic/gin"

	"gitee.com/lcc_dr/restful-api-demo/apps"
	"gitee.com/lcc_dr/restful-api-demo/apps/host"
	"gitee.com/lcc_dr/restful-api-demo/apps/host/impl"
	"github.com/go-playground/validator/v10"
	"github.com/infraboard/mcube/logger"
	"github.com/infraboard/mcube/logger/zap"
)

var ginimpl = &HandleHostService{}
var validate *validator.Validate

//定义 gin handler 数据结构
type HandleHostService struct {
	l logger.Logger

	svc host.HostService
}

func NewHandleHostService() *HandleHostService {

	return &HandleHostService{
		l: zap.L().Named("host"),
	}
}

// 从IOC注册中心获HostService 实例
func (h *HandleHostService) Config() {

	// h.svc = apps.HostService
	h.svc = apps.GetImpl(impl.AppName).(host.HostService)
}

func (H *HandleHostService) Name() string {
	return impl.AppName
}

//gin 路由注册
func (h *HandleHostService) Registry(r gin.IRouter) {

	r.POST("/api/v1/host", h.createHost)
	r.GET("/api/v1/host/:id", h.queryDescribeHost)
	r.GET("/api/v1/host", h.queryHosts)
	r.DELETE("/api/v1/host/:id", h.deleteHost)
	r.PATCH("/api/v1/host/:id", h.updatePatchHost)
	r.PUT("/api/v1/host/:id", h.updatePutHost)

}

func init() {

	apps.RegistryGin(ginimpl)
}
